<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>修改信息</title>
    <link href="/static/bootstrap-3.3.7-dist/css/bootstrap.css" rel="stylesheet">
    <script src="/static/jquery/jquery-3.3.1.min.js"></script>
    <script src="/static/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    <script>
        $(function(){

            $("#btn").click(function () {

                var json={ "locationId":$(":input[name='locationId']").val(),"streetAddress":$(":input[name='streetAddress']").val(),"postalCode":$(":input[name='postalCode']").val(),
                    "city":$(":input[name='city']").val(),"stateProvince":$(":input[name='stateProvince']").val(),"countryId":$(":input[name='countryId']").val()};
                alert(JSON.stringify(json))
                $.ajax({
                    url:"/location/update",
                    data:JSON.stringify(json),
                    type:"post",
                    contentType:"application/json",
                    success:function (returnData) {
                        if(returnData=="1"){
                            location.href="/location?"+$("#url").text();

                        }else{
                            alert("出错了")
                        }
                    }

                })
            })
        })
    </script>

</head>
<body>
<h1>修改信息</h1>
<hr/>
<form class="form-horizontal">
    <div class="form-group" style="visibility: hidden" >
        <label class="col-sm-2 control-label">地区编号</label>
        <div class="col-sm-5">
            <input type="text" name="locationId" class="form-control" placeholder="地区编号" value="${location.locationId}">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">街道地址</label>
        <div class="col-sm-5">
            <input type="text" name="streetAddress" class="form-control" placeholder="街道地址" value="${location.streetAddress}">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">邮政编码</label>
        <div class="col-sm-5">
            <input type="email" name="postalCode" class="form-control" placeholder="邮政编码" value="${location.postalCode}">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">城市</label>
        <div class="col-sm-5">
            <input type="text" name="city" class="form-control" placeholder="城市" value="${location.city}">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">省份</label>
        <div class="col-sm-5">
            <input type="text"  name="stateProvince" class="form-control" placeholder="省份" value="${location.stateProvince}">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">国籍</label>
        <div class="col-sm-5">
            <select class="form-control" name="countryId">
                <option value="">请选择国籍</option>
                <c:forEach items="${countries}" var="c">
                    <option value="${c.countryId}" ${c.countryId.equals(location.countryId)?"selected='selected'":""}>${c.countryName}</option>
                </c:forEach>
            </select>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="button" class="btn btn-default" id="btn">修改</button>
        </div>
    </div>
    <span id="url" style="visibility: hidden">${url}&pageNum=${pageInfo.pageNum}</span>
</form>
</body>
</html>
